import Vue from 'vue';
import Router from 'vue-router';
Vue.use(Router);


// 全局路由
export const globalRoutes = [
	{
		path: '',
		component: () => import('@/views/main'),
		redirect: '/userOperation',
		children: [
			{
				path: '/userOperation',
				component: () => import('@/components/UserOperation'),
			},
			{
				path: '/goodOperation',
				component: () => import('@/components/GoodOperation'),
			},
			{
				path: '/addGood',
				component: () => import('@/components/AddGood'),
			},
			{
				path: '/orderOperation',
				component: () => import('@/components/OrderOperation'),
			},
			{
				path: '/logOperation',
				component: () => import('@/components/LogOperation'),
			}
		]
	},

	{
		path: '/login',
		component: () => import('@/views/login')

	}
]

// 防止连续点击多次路由报错
let routerPath = Router.prototype.push;
Router.prototype.push = function push(location) {
	return routerPath.call(this, location).catch(err => err)
}

export default new Router({
	mode: 'history', // 去掉url中的#
	routes: globalRoutes,
	base: process.env.BASE_URL
});
